package org.inspursc.s0517.health.common.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.inspursc.s0517.health.common.dao.SysPermissionDao;
import org.inspursc.s0517.health.common.entity.SysPermission;
import org.inspursc.s0517.health.common.service.SysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Slf4j
@Service
public class SysPermissionServiceImpl implements SysPermissionService {

    @Autowired
    private SysPermissionDao permissionDao;

    @Override
    public SysPermission save(SysPermission permission) {
        return permissionDao.save(permission);
    }

    @Override
    public SysPermission findById(Integer id) {
        return permissionDao.getOne(id);
    }

    @Override
    public List<SysPermission> findAll() {
        return permissionDao.findAll();
    }

    @Override
    public List<SysPermission> findByUserId(Integer userId) {
        return permissionDao.findByUserId(userId);
    }

    @Override
    public List<SysPermission> findByGroupId(Integer groupId) {
        return permissionDao.findByGroupId(groupId);
    }

    @Override
    @Transactional
    public boolean deleteById(Integer id) {
        try {
            permissionDao.deleteById(id);
            return true;
        } catch (Exception e) {
            log.error("【删除失败】", e.getMessage());
            return false;
        }
    }
}
